﻿@{
    var grid = Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "gvOrder";
        settings.KeyFieldName = "ID";
        settings.CallbackRouteValues = new { Controller = "Order", Action = "OrderRowPartial" };
        settings.CustomBindingRouteValuesCollection.Add(GridViewOperationType.Paging, new { Controller = "Order", Action = "OrderPagingRowPartial" });
        settings.CustomBindingRouteValuesCollection.Add(GridViewOperationType.Filtering, new { Controller = "Order", Action = "OrderFilteringRowPartial" });
        settings.CustomBindingRouteValuesCollection.Add(GridViewOperationType.Sorting, new { Controller = "Order", Action = "OrderSortingRowPartial" });
        settings.CustomActionRouteValues = new { Controller = "Order", Action = "ApplyFilterExpressionPartial" };

        settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
        settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
        settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.SettingsPopup.EditForm.Modal = true;
        settings.CommandColumn.HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        settings.SettingsBehavior.ConfirmDelete = true;
        settings.SettingsPopup.EditForm.Width = new System.Web.UI.WebControls.Unit(900);
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.SettingsText.PopupEditFormCaption = "Order Management";
        settings.ControlStyle.CssClass = "edit-form";
        settings.SettingsPager.PageSize = Session["PageSize"] != null ? (int)Session["PageSize"] : 10;
        settings.SettingsBehavior.AllowFocusedRow = true;
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowSelectCheckbox = true;
        settings.ClientSideEvents.Init = @"function(s,e){ 
            s.UnselectAllRowsOnPage();
        }";
        settings.ClientSideEvents.BeginCallback = "gvOrderBeginCallback";

        settings.Columns.Add("Name");
        settings.Columns.Add("Description");
        settings.Columns.Add("Position");

        settings.Columns.Add(column =>
        {
            column.FieldName = "UpdatedDate";
            column.Caption = "Updated Date";
            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "UpdatedBy";
            column.Caption = "Updated By";
            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
        });

        settings.Settings.ShowFilterRowMenu = settings.Settings.ShowFilterRow;
        settings.CommandColumn.ClearFilterButton.Visible = settings.Settings.ShowFilterRow;
        settings.SettingsPager.Position = System.Web.UI.WebControls.PagerPosition.Bottom;
        settings.SettingsPager.FirstPageButton.Visible = true;
        settings.SettingsPager.LastPageButton.Visible = true;
        settings.SettingsPager.PageSizeItemSettings.Visible = true;
        settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };

    });

    
    @grid.BindToCustomData(Model).GetHtml()
}